package com.jf.cloud.service.sysmanager.config;

import java.nio.charset.Charset;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.jf.cloud.service.sysmanager.support.SessionInterceptor;

/**
 * Created with IntelliJ IDEA.
 * User: LangK
 * Date: 2017/9/9
 * Time: 14:23
 * Description:
 */
@Configuration
public class WebMvcConfigurer extends WebMvcConfigurerAdapter {

    @Autowired
    private SessionInterceptor sessionInterceptor;    

    /**
     * 根指向
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
    	registry.addViewController("/").setViewName("welcome");
        
    	// 账号管理
        registry.addViewController("/accountManage/list").setViewName("jsp/card/accountManage_list");
        registry.addViewController("/accountManage/toAdd").setViewName("jsp/card/accountManage_add");
        registry.addViewController("/accountManage/toAllot").setViewName("jsp/card/accountManage_allot");
        
        // 账号处理
        registry.addViewController("/kfManage/list").setViewName("jsp/card/kfManage_list");
        registry.addViewController("/kfManage/toSumbit").setViewName("jsp/card/kfManage_sumbit");
        
        // 客服操作账号历史查询
        registry.addViewController("/kfOptRecord/list").setViewName("jsp/card/kfOptRecord_list");
        
        // 布谷官网用户提交联系方式
        registry.addViewController("/buguUserInfo/list").setViewName("jsp/card/buguUserInfo_list");
        
        
        // 修改密码
        registry.addViewController("/staff/passwordUpdate").setViewName("jsp/system/staff_pwd_update");
        
        // 基础类型维护
        registry.addViewController("/baseType/list").setViewName("jsp/base/baseType_list");
        registry.addViewController("/baseType/toAddBaseType").setViewName("jsp/base/baseType_add");
        registry.addViewController("/baseType/smallTypelist").setViewName("jsp/base/baseSmallType_list");
        registry.addViewController("/baseType/toAddBaseSmallType").setViewName("jsp/base/baseSmallType_add");
        registry.addViewController("/basePropConfig/list").setViewName("jsp/base/basePropsConfig_list");
        registry.addViewController("/basePropConfig/toAddBaseProps").setViewName("jsp/base/basePropsConfig_add");

        // 物品
        registry.addViewController("/gameGoodsType/list").setViewName("jsp/goods/gameGoodsType_list");
        registry.addViewController("/gameGoodsType/toAddGoodsType").setViewName("jsp/goods/gameGoodsType_add");
        registry.addViewController("/gameGoodsType/smallTypelist").setViewName("jsp/goods/gameGoodsSmallType_list");
        registry.addViewController("/gameGoodsType/toAddGoodsSmallType").setViewName("jsp/goods/gameGoodsSmallType_add");

        // 帮助文档
        registry.addViewController("/baseHelpDoc/list").setViewName("jsp/system/baseHelpDoc_list");
        registry.addViewController("/baseHelpDoc/toAddBaseHelpDoc").setViewName("jsp/system/baseHelpDoc_add");

        // roway 联系我们
        registry.addViewController("/contactOffical/list").setViewName("jsp/system/contactOffical_list");
        registry.addViewController("/contactOffical/toAdd").setViewName("jsp/system/contactOffical_add");

        //公告
        registry.addViewController("/baseAffiche/list").setViewName("jsp/system/baseAffiche_list");
        registry.addViewController("/baseAffiche/toAdd").setViewName("jsp/system/baseAffiche_add");

        // 用户管理
        registry.addViewController("/userInfo/list").setViewName("jsp/user/userInfo_list");
        registry.addViewController("/userInfo/userDetail").setViewName("jsp/user/userInfo_detail");

        // 交易相关
        registry.addViewController("/tradeReasons/list").setViewName("jsp/trade/tradeReasons_list"); // 原因列表
        registry.addViewController("/tradeReasons/toAdd").setViewName("jsp/trade/tradeReasons_add"); // 原因 添加
        registry.addViewController("/tradeGoods/list").setViewName("jsp/trade/tradeGoods_list"); // 商品列表
        registry.addViewController("/tradeOrdersCx/list").setViewName("jsp/trade/tradeOrdersCx_list"); // 订单查询列表
        registry.addViewController("/baseTradeSxFee/config").setViewName("jsp/trade/baseTradeSxFee_config"); // 手续费配置列表
        registry.addViewController("/baseTradeSxFee/toAdd").setViewName("jsp/trade/baseTradeSxFee_add"); // 手续费配置 新增
        registry.addViewController("/basePublishGoodsDesc/config").setViewName("jsp/trade/basePublishGoodsDesc_config"); // 商品描述配置列表
        registry.addViewController("/basePublishGoodsDesc/toAdd").setViewName("jsp/trade/basePublishGoodsDesc_add"); // 商品描述配置 新增
        
        // 财务管理
        registry.addViewController("/tradeFinDrawDetailCl/list").setViewName("jsp/fund/tradeFinDrawDetailCl_list"); // 提现订单处理列表
        registry.addViewController("/tradeFinDrawDetailCx/list").setViewName("jsp/fund/tradeFinDrawDetailCx_list"); // 提现订单查询列表
        registry.addViewController("/fundFinanceMoneyFlowDetail/list").setViewName("jsp/fund/fundFinanceMoneyFlowDetail_list"); // 资金明细管理列表
        
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
        super.addViewControllers(registry);
    }

//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/common/**").addResourceLocations("classpath:/common/");
//        registry.addResourceHandler("/advert/**").addResourceLocations("classpath:/advert/");
//        registry.addResourceHandler("/css/**").addResourceLocations("classpath:/css/");
//        registry.addResourceHandler("/images/**").addResourceLocations("classpath:/images/");
//        registry.addResourceHandler("/js/**").addResourceLocations("classpath:/js/");
//        registry.addResourceHandler("/fonts/**").addResourceLocations("classpath:/fonts/");
//        registry.addResourceHandler("/MP_verify_EmeQlrDpUR8SisyI.txt").addResourceLocations("classpath:/MP_verify_EmeQlrDpUR8SisyI.txt");
//        registry.addResourceHandler("/view/**").addResourceLocations("classpath:/META-INF/resources/jsp/");
//        super.addResourceHandlers(registry);
//    }

    /**
     * 拦截请求
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(sessionInterceptor).addPathPatterns("/**").excludePathPatterns("/wap/**").excludePathPatterns("/");
        super.addInterceptors(registry);
    }


    @Bean
    public HttpMessageConverter<String> responseBodyConverter() {
        StringHttpMessageConverter converter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
        return converter;
    }

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        super.configureMessageConverters(converters);
        converters.add(responseBodyConverter());
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").allowedHeaders("*").allowedMethods("*").allowedOrigins("*");
        super.addCorsMappings(registry);
    }
}